home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-ppc-src / ar / amiga.c next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  107 lines

  1. /* $VER: ar amiga.c V0.1 (31.01.98)
  2.  *
  3.  * This file is part of ar, a portable archive maintanance
  4.  * utility for normal and BSD-style archives.
  5.  * Copyright (c) 1999  Frank Wille
  6.  *
  7.  * ar is freeware and part of the portable and retargetable ANSI C
  8.  * compiler vbcc, copyright (c) 1995-99 by Volker Barthelmann.
  9.  * ar may be freely redistributed as long as no modifications are
  10.  * made and nothing is charged for it. Non-commercial usage is allowed
  11.  * without any restrictions.
  12.  * EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
  13.  * SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
  14.  *
  15.  *
  16.  * v0.1  (31.01.99) phx
  17.  *       First working version, which only supports 'q' (quick append)
  18.  *       and 't' (table of contents), reads and writes normals and
  19.  *       BSD-style archives. Symbol table will not be created!
  20.  * v0.0  (31.01.99) phx
  21.  *       File created.
  22.  */
  23.  
  24. #ifdef AMIGA
  25. #include <exec/types.h>
  26. #include <dos/dosasl.h>
  27. #include <dos/dosextens.h>
  28. #include <proto/dos.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31.  
  32. #define NAMEBUF 256
  33.  
  34.  
  35.  
  36. static int pattmatch(int first,int nargs,char *args[],char **argv)
  37. {
  38.   struct AnchorPath *ap;
  39.   char *s;
  40.   int i,n;
  41.  
  42.   if (ap = (struct AnchorPath *)calloc(sizeof(struct AnchorPath)+NAMEBUF,1)) {
  43.     ap->ap_Strlen = NAMEBUF;
  44.     ap->ap_BreakBits = 0;
  45.   }
  46.   else
  47.     return (0);
  48.  
  49.   for (i=n=first; i<nargs; i++) {
  50.     if (!MatchFirst((STRPTR)args[i],ap)) {
  51.       do {
  52.         if (argv) {
  53.           if (s = malloc(strlen(ap->ap_Buf)+1)) {
  54.             strcpy(s,ap->ap_Buf);
  55.             argv[n] = s;
  56.           }
  57.           else {
  58.             free(ap);
  59.             return (0);
  60.           }
  61.         }
  62.         n++;
  63.       }
  64.       while (!MatchNext(ap));
  65.     }
  66.     else {
  67.       /* no existing file name, just copy original string */
  68.       if (argv)
  69.         argv[n] = args[i];
  70.       n++;
  71.     }
  72.   }
  73.   free(ap);
  74.   return (n);
  75. }
  76.  
  77.  
  78. char **expand_args(int *argc,int nargs,char *args[],int first)
  79. /* do pattern matching on arguments, allocate new argv array */
  80. /* 'first' is the index of the first argument to do patt.matching for */
  81. {
  82.   int i;
  83.   char **argv;
  84.  
  85.   if (first > nargs)
  86.     first = nargs;
  87.   if (*argc = pattmatch(first,nargs,args,NULL)) {
  88.     if (argv = malloc((*argc+1) * sizeof(char *))) {
  89.       argv[*argc] = NULL;
  90.       for (i=0; i<first; i++)
  91.         argv[i] = args[i];
  92.       if (pattmatch(first,nargs,args,argv))
  93.         return (argv);
  94.       else
  95.         free(argv);
  96.     }
  97.   }
  98.  
  99.   /* expand_args failed, use original argument list */
  100.   argv = args;
  101.   *argc = nargs;
  102.   return (argv);
  103. }
  104.  
  105.  
  106. #endif /* AMIGA */
  107.